import functools
class Solution(object):
    def earliestAndLatest(self, n, firstPlayer, secondPlayer):
        @functools.cache
        def dfs(n, f, s):
            if f + s == n + 1:
                return 1, 1
            else:
                mirror_f = n + 1 - f
                mirror_s = n + 1 - s
                st = [f, s, mirror_f, mirror_s]
                st.sort()
                s_index = st.index(s)
                f_index = st.index(f)
                l_index, r_index = min(s_index, f_index), max(s_index, f_index)
                mid_num = (st[2] - st[1]) // 2
                min_ans = float('inf')
                max_ans = - float('inf')
                for i in range(st[0]):
                    for j in range(st[1] - st[0]):
                        if (l_index, r_index) == (0, 1):
                            next_min, next_max = dfs((n + 1) // 2, i + 1, i + j + 2)
                        if (l_index, r_index) == (0, 2):
                            next_min, next_max = dfs((n + 1) // 2, i + 1, i + j + mid_num + 2)
                        if (l_index, r_index) == (0, 3):
                            next_min, next_max = dfs((n + 1) // 2, i + 1, i + mid_num + st[1] - st[0] + 1)
                        if (l_index, r_index) == (1, 2):
                            next_min, next_max = dfs((n + 1) // 2, i + j + 1, i + j + mid_num + 2)
                        if (l_index, r_index) == (1, 3):
                            next_min, next_max = dfs((n + 1) // 2, i + j + 1, i + mid_num + st[1] - st[0] + 1)
                        if (l_index, r_index) == (2, 3):
                            next_min, next_max = dfs((n + 1) // 2, i + j + mid_num + 1, i + mid_num + st[1] - st[0] + 1)
                        min_ans = min(min_ans, 1 + next_min)
                        max_ans = max(max_ans, 1 + next_max)
                return min_ans, max_ans
        return list(dfs(n, firstPlayer, secondPlayer))

data = Solution()
n = 11
firstPlayer = 2
secondPlayer = 4
print(data.earliestAndLatest(n, firstPlayer, secondPlayer))
n = 5
firstPlayer = 1
secondPlayer = 5
print(data.earliestAndLatest(n, firstPlayer, secondPlayer))